package android.adapters;

import java.util.List;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.content.Context;

import android.model.BankItemDialogue;
import android.activity.R;

public class BankAdapterDialogue extends BaseAdapter {
	
	List<BankItemDialogue> items;
	LayoutInflater inflater;
	
	static class BankItemHolder {
		
		TextView sentenceView;
		TextView pronounceView;
		
	}
	
	public BankAdapterDialogue(Context ctx, List<BankItemDialogue> items) {
		this.items = items;
		inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	public int getCount() {
		return items.size();
	}

	public Object getItem(int position) {
		return items.get(position);
	}

	public long getItemId(int position) {
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) {
		BankItemHolder bih;
		if (convertView == null) {
			RelativeLayout rl = (RelativeLayout) inflater.inflate(R.layout.v_bank_item_dialogue, null);
			convertView = rl;
			bih = new BankItemHolder();
			bih.sentenceView = (TextView) rl.findViewById(R.id.txtSentence);
			bih.pronounceView = (TextView) rl.findViewById(R.id.txtPronounce);
			convertView.setTag(bih);
		} else {
			bih = (BankItemHolder) convertView.getTag();
		}

		bih.sentenceView.setText(items.get(position).getSentence());
		bih.pronounceView.setText(items.get(position).getPronounce());
		return convertView;
	}
	
	public void clear() {
		items.clear();
	}

	public void add(BankItemDialogue item) {
		items.add(item);
	}

}
